GoogleAuth   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 29
dl 0
loc 35
c 0
b 0
f 0
rs 10

2 Functions

Rating   Name   Duplication   Size   Complexity  
A signInNative 0 8 1
A getBrowserSignInProvider 0 7 1
1
import { Injectable } from "@angular/core";
2
import { AngularFireAuth } from "@angular/fire/auth";
3
import { GooglePlus } from "@ionic-native/google-plus/ngx";
4
import { Platform } from "@ionic/angular";
5
import { auth } from "firebase/app";
6
import { UniFirebaseLoginConfigProvider } from "../../config/uni-firebase-login-config-provider";
7
import { AbstractAuth } from "../../providers/abstract-auth";
8
import { IAuthProvider } from "../../providers/i-auth-provider";
9
import { IGoogleAuthOptions } from "./i-google-auth-options";
10
11
@Injectable()
12
export class GoogleAuth extends AbstractAuth implements IAuthProvider {
13
  public readonly providerKey = "google";
14
  public readonly defaultOptions: IGoogleAuthOptions = {
15
    offline: true,
16
    scopes: "profile email",
17
    signInType: "popup",
18
  };
19
20
  public constructor(
21
    private googleAuth: GooglePlus,
22
    angularFireAuth: AngularFireAuth,
23
    platform: Platform,
24
    config: UniFirebaseLoginConfigProvider,
25
  ) {
26
    super(angularFireAuth, platform, config);
27
  }
28
29
  public async signInNative(options: any): Promise<auth.UserCredential | null> {
30
    const mergedOptions = Object.assign({}, this.defaultOptions, options);
31
32
    const googleUser = await this.googleAuth.login(mergedOptions);
33
34
    return await this.angularFireAuth.auth.signInWithCredential(
35
      auth.GoogleAuthProvider.credential(googleUser.idToken),
36
    );
37
  }
38
39
  protected getBrowserSignInProvider() {
40
    const provider = new auth.GoogleAuthProvider();
41
    provider.setCustomParameters({
42
      prompt: "select_account",
43
    });
44
    return provider;
45
  }
46
}
47